package com.zhb.zhbojbackendquestionservice.controller.inner;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhb.zhbojbackendmodel.model.dto.questionsubmit.QuestionSubmitQueryDTO;
import com.zhb.zhbojbackendmodel.model.entity.Question;
import com.zhb.zhbojbackendmodel.model.entity.QuestionSubmit;
import com.zhb.zhbojbackendquestionservice.service.QuestionService;
import com.zhb.zhbojbackendquestionservice.service.QuestionSubmitService;
import com.zhb.zhbojbackendserviceclient.service.QuestionFeignClient;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 该服务仅内部调用，不是给前端的
 */
@RestController
@RequestMapping("/inner")
public class QuestionInnerController implements QuestionFeignClient {

    @Resource
    private QuestionService questionService;

    @Resource
    private QuestionSubmitService questionSubmitService;

    @Override
    public List<QuestionSubmit> list(QuestionSubmitQueryDTO questionSubmitQueryDTO) {
        QueryWrapper<QuestionSubmit> submitQueryWrapper = new QueryWrapper<>();
        submitQueryWrapper.eq("userId", questionSubmitQueryDTO.getUserId());
        if (questionSubmitQueryDTO.getQuestionId()!=null){
            submitQueryWrapper.eq("questionId", questionSubmitQueryDTO.getQuestionId());
        }
        return questionSubmitService.list(submitQueryWrapper);
    }

    @Override
    public Question getOne(long questionId) {
        return questionService.getOne(new QueryWrapper<Question>().eq("id", questionId));
    }

    @GetMapping("/get/id")
    @Override
    public Question getQuestionById(@RequestParam("questionId") long questionId) {
        return questionService.getById(questionId);
    }
    @PostMapping("/update")
    @Override
    public Boolean updateQuestionById(@RequestBody Question question) {
        return questionService.updateById(question);
    }

    @GetMapping("/question_submit/get/id")
    @Override
    public QuestionSubmit getQuestionSubmitById(@RequestParam("questionId") long questionSubmitId) {
        return questionSubmitService.getById(questionSubmitId);
    }



    @PostMapping("/question_submit/update")
    @Override
    public boolean updateQuestionSubmitById(@RequestBody QuestionSubmit questionSubmit) {
        return questionSubmitService.updateById(questionSubmit);
    }

}
